import 'package:flutter/material.dart';

class ResponsiveColumn extends StatelessWidget{
  const ResponsiveColumn({super.key,required this.children});

  final List<Widget> children;



  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints){
        if(constraints.maxWidth < 200){
          return Column(children:children,mainAxisSize: MainAxisSize.min);
        }else{
          var _children = <Widget>[];
          for(var i =0;i< children.length;i+=2){
            if(i + 1 < children.length){
              _children.add(Row(
                children: [children[i],children[i + 1]],
                mainAxisSize: MainAxisSize.min,
              ));
            }else{
              _children.add(children[i]);
            }
          }

          return Column(children: _children,mainAxisSize: MainAxisSize.min);
        }
      }
    );
  }

}

class LayoutBuilderRouter extends StatelessWidget{
  @override
  Widget build(Object context) {
    var _children = List.filled(6, Text("A"));
    return Column(
      children: [
        SizedBox(
          width: 190,
          child: ResponsiveColumn(children: _children),
        ),
        ResponsiveColumn(children: _children),
        LayoutLogPrint(child:Text("xx")) // 下面介绍
      ],
    );
  }
  
}

class LayoutLogPrint<T> extends StatelessWidget{

  final Widget child;
  final T? tag;

  const LayoutLogPrint({super.key,this.tag,required this.child});


  @override
  Widget build(Object context) {
    return
    LayoutBuilder(
      builder: (_,constraints) {
        assert((){
          print("${tag ?? key ?? child} : $constraints");
          return true;
        }());
        return child;
      }
    );
  }
  
}